/*
 * exame_2010_11_recurso.c
 *
 *  Created on: Jun 15, 2012
 *      Author: ubuntu
 */

#include <stdlib.h>
#include <stdio.h>

int decit(int a) {

	int a_decomp = a;
	while (a_decomp > 0) {
		int digito = a_decomp % 10;
		printf("%d ", digito);

		a_decomp = (a_decomp - digito) / 10;
	}
	printf("\n");
	return 0;

}

int decrec(int a) {

	int a_decomp = a;
	if (a_decomp > 0) {
		int digito = a_decomp % 10;
		printf("%d ", digito);

		a_decomp = (a_decomp - digito) / 10;

		return decrec(a_decomp);
	} else {
		printf("\n");
	}

	return 0;
}




int main(int argc, char **argv) {

	if (argc < 2) {
		fprintf(stderr, "Usage %s <n>\n", argv[0]);
		exit(EXIT_FAILURE);

	}

	int a = atoi(argv[1]);

	printf("Iterativa\n");
	decit(a);

	printf("Recursiva\n");
	decrec(a);
	return 0;


}
